package apuesta.hibernate;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class HibernateFactoryApuesta {

    private static final SessionFactory sessionFactory;
    private static final ServiceRegistry serviceRegistry;
    private static Configuration hibConfiguration;
    
    static {
        try {

            hibConfiguration = new Configuration().configure("/hibernate.cfg.xml");
            serviceRegistry = new ServiceRegistryBuilder().applySettings(hibConfiguration.getProperties()).buildServiceRegistry();
            //System.out.println("3>"+serviceRegistry);

            sessionFactory = hibConfiguration.buildSessionFactory(serviceRegistry);
            //System.out.println("4>"+serviceRegistry);
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
    
    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
	

	
}
